(include-book "../src/acl2/grid")
(include-book "generators/grid-data-generator")
(include-book "testing" :dir :teachpacks)

;;;Tests for the grid utilities provided in grid.lisp.
;;;- Getting and setting cells
;;;- some procedures for flattening grids
;;;- procedures for getting the bounds of a grid


;;Test that, after setting a cell, you can get it.
(defproperty get-set-lifelike
  (a-grid :value (random-lifelike-grid 50 50 1/10)
   x :value (random-integer)
   y :value (random-integer))
  (equal (lifelike-grid-get
          (lifelike-grid-set a-grid x y t)
          x y) t))

;;Test that, after setting a cell, you can get it.
;;for elementary grids
(defproperty get-set-elementary
  (a-grid :value (random-elementary-grid 50 1/10)
   x :value (random-integer))
  (equal (elementary-grid-get
          (elementary-grid-set a-grid x t)
          x ) t))


;;Test flattening elementary grids
;;(flattening lifelike grids uses 
;; nested-avl-flatten-to-cells from
;; avl-utils.
(defproperty elem-get-all-poses-gets-all-poses
  (poses :value (cons (random-integer) (random-list-of (random-integer)))
   rand-pos :value (random-between 0 (1- (length poses)))
   pos-to-check :value (nth rand-pos poses)
   a-grid :value (elementary-grid-set-multiple (empty-lifelike-grid)
                                               poses t))
  (member-equal pos-to-check (elementary-grid-get-all-live-cells a-grid)))


;;Testing lifelike boundaries
;;
(defproperty verify-bounds-are-true-endpoints-lifelike
  (lowest-x :value (random-integer)
   biggest-x :value (random-between lowest-x (* 10 (abs lowest-x)))
   lowest-y :value (random-integer)
   biggest-y :value (random-between lowest-y (* 10 (abs lowest-y)))
   all-cells :value 
      (append
        (list (cell lowest-x (random-between lowest-y biggest-y))
              (cell biggest-x (random-between lowest-y biggest-y))
              (cell (random-between lowest-x biggest-x) lowest-y)
              (cell (random-between lowest-x biggest-x) biggest-y))
       (random-list-of
        (cell (random-between lowest-x biggest-x)
              (random-between lowest-y biggest-y))))
   my-grid :value (lifelike-grid-set-multiple-cells (empty-lifelike-grid)
                                               all-cells
                                               t)
   expected-val :value  (ll-bounds lowest-x biggest-x biggest-y lowest-y)
   actual-val :value (get-ll-bounds my-grid))
  (equal expected-val actual-val))

(defproperty verify-bounds-are-true-endpoint-elementary
  (lowest-x :value (random-integer)
   biggest-x :value (random-between lowest-x (* 10 (abs lowest-x)))
  all-cells :value 
      (append
        (list lowest-x biggest-x)
       (random-list-of (random-between lowest-x biggest-x)))
   my-grid :value (elementary-grid-set-multiple (empty-lifelike-grid)
                                               all-cells
                                               t)
   expected-val :value  (el-bounds lowest-x biggest-x)
   actual-val :value (get-el-bounds my-grid))
  (equal expected-val actual-val))



   